package com.bzframework.pro.example.controller;

import com.bzframework.pro.authorize.annotation.Authorization;
import com.bzframework.pro.authorize.adapter.ReactiveServiceCrudControllerAdapter;
import com.bzframework.pro.example.entity.ExampleEntity;
import com.bzframework.pro.example.service.ExampleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.hswebframework.web.crud.service.ReactiveCrudService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * @Author bingzhong
 * @Date 2024/11/19 10:52
 * @Description
 */
@Tag(name = "基本增删改查结构")
@RestController
@RequestMapping("/example")
@RequiredArgsConstructor
public class ExampleController implements ReactiveServiceCrudControllerAdapter<ExampleEntity, String> {

    private final ExampleService exampleService;

    @Override
    public ReactiveCrudService<ExampleEntity, String> getService() {
        return exampleService;
    }

    @GetMapping
    @Operation(summary = "测试示例接口")
    public Mono<String> testAuth(){
        return Mono.just("authed");
    }

    @GetMapping("/auth")
    @Operation(summary = "测试示例接口")
    @Authorization(ignore = true)
    public Mono<String> testNoneAuth(@RequestParam(required = false, defaultValue = "noAuth") String name){
        return Mono.just(name);
    }

    @GetMapping("/admin")
    @Operation(summary = "测试管理员权限接口")
    @Authorization(admin = true)
    public Mono<String> testAdminAuth(@RequestParam(required = false, defaultValue = "adminAuth") String name){
        return Mono.just(name);
    }


}
